package sensornetwork;

import snifc.LinkIfc;
import snifc.PacketIfc;
import snifc.sensor.IOPortsIfc;
import sensornetwork.sensor.IOPorts;


public class Link implements LinkIfc {
	private PacketIfc packet1;
	private PacketIfc packet2;
	private IOPorts port1;
	private IOPorts port2;
	private int idLink;
	
	public Link (int idLink, IOPortsIfc entry, IOPortsIfc exit) {
		this.port1 = (IOPorts) entry;
		this.port2 = (IOPorts)exit;
		this.idLink = idLink;
	}
	
	public void transmit (PacketIfc p, IOPortsIfc from) {
		if (this.port1.compareTo(from) == 0){
			packet2 = p;
		} else {
			packet1 = p;
		}
	}
	
	public PacketIfc getPendingPacket (IOPortsIfc s) {
		if (this.port1.compareTo(s) == 0){
			return packet1;
		} else {
			return packet2;
		}
	}
	
	public int getId() {
		return this.idLink;
	}
	
}
